/*
 * distributor_emulator.h
 *
 *  Created on: Oct 9, 2012
 *      Author: andrey
 *
 * default output lines are PA5 and PA7
 *
 * white wire pin is high 1/12 of period, then low for 2/12 of period, then this loop
 * repeats three more times within each revolution period - i.e. four times total
 *
 * green wire - high for a little bit in the end of the period and for first 2/12
 *
 * since the actual distributor sensors are disconnecting or grounding we need a
 * transistor, with ground wired to collector, ECU wired to emitter and base wired to
 * out output pins
 *
 * 945 transistor: base on the right if looking at the markings (I use white wires)
 * 945 transistor: collector is in the center (I use black wires)
 * 945 transistor: emitter on the left if looking at the markings (I use red wires)
 *
 * 2001 transistor: collector is on the left if looking at the markings
 * 2001 transistor: base on the right if looking at the markings
 *
 */

#ifndef DISTRIBUTOR_EMULATOR_H_
#define DISTRIBUTOR_EMULATOR_H_

#include <time.h>
#include "main.h"

// 50% duty wave - limping mode chip input
#define DE_WAVE_1_PIN DE_PA14
// 50% duty wave - limping mode chip input
#define DE_WAVE_2_PIN DE_PA15

#define DE_ADC_IO_PORT GPIOB
#define DE_ADC_WAVE_PIN 1

//#define ST2MS(st) (1000L * (st) / CH_FREQUENCY )


int waveState(time_t start, time_t now, myfloat waveLen, myfloat leftSide,
		myfloat rightSide);

myfloat floatmod(myfloat value, myfloat divider);
void emulateDistributor(time_t start_time, int cycleLength);


#endif /* DISTRIBUTOR_EMULATOR_H_ */
